$(document).ready(function() {
    var noticeId = getUrlParms("noticeId");
    console.log(noticeId);
    $.ajax({
        url: "http://localhost:8080/notice/queryANotice",
        type: "GET",
        async: true,
        data: "noticeId=" + noticeId,
        dataType: "json",
        success: function (data) {
            console.log(data)
            var notice=data.data.noticeTeacher;
            $("input[name='noticeTitle']").val(notice.noticeTitle);
            //$("#select2 option:selected").val(notice.noticeAuthor);
            $("#select2 option[value='"+notice.noticeAuthor+"']").attr("selected","selected");
            tinyMCE.activeEditor.setContent(notice.noticeContent);
            var temp=notice.noticeContent
            temp = temp.replace("&lt;p&gt;", "").replace("&lt;/p&gt;", "");//3
            tinyMCE.activeEditor.setContent(temp);
            $("#mce_23").remove();
           // $("#mce_18-body").remove();//1
            /* var temp = partyActivity.partyActivityDescription;//3
            temp = temp.replace("&lt;p&gt;", "").replace("&lt;/p&gt;", "");//3
            tinyMCE.activeEditor.setContent(temp);
            $("#mce_23").remove();//2*/
        }
    });

});

$(document).on('click', '#update-btn', function() {
    var noticeId = getUrlParms("noticeId");
    var $noticeTitle=$("input[name='noticeTitle']").val();
    var $noticeAuthor=$("#select2 option:selected").val();
    var $noticeContent=html_encode(tinyMCE.activeEditor.getContent());
    //封装成对象提交
    var data = {
        noticeId:noticeId,
        noticeTitle:$noticeTitle,
        noticeContent:$noticeContent,
        noticeAuthor:$noticeAuthor,
    };
    $.ajax({
        url: "http://localhost:8080/notice/updateNotice",
        type: "POST",
        async: false,
        data:JSON.stringify(data),
        dataType: "json",
        contentType:"application/json",
        success:function () {
            layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            setTimeout(function () {
                layer.msg('更新成功')
            },1500);

            var index = parent.layer.getFrameIndex(window.name);
            setTimeout(function(){
                parent.layer.close(index)
            }, 2000);
            parent.location.reload()
        },
        error:function () {
            layer.alert("网络在开小差~再试一次吧！");
        }
    });
});


function getUrlParms(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)
        return unescape(r[2]);
    return null;
}

